import subprocess 
import os
import string

p = subprocess.Popen("cat pkgs", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 
number = 0

for line in p.stdout.readlines():
	line = line.rstrip()
	print line
	
	cmd = "java -jar googleplaycrawler-0.2.jar -f crawler.conf permissions " + line + "| grep ACCOUNTS"
	
	q = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

	exist = False
	for line2 in q.stdout.readlines():
		line2 = line2.rstrip()
		if string.find(line2, "MANAGE_ACCOUNTS") != -1 or string.find(line2, "AUTHENTICATE_ACCOUNTS") != -1 or string.find(line2, "USE_CREDENTIALS") != -1:
			exist = True
			print line2
	
	if exist == True:
		number += 1
		print "exist"
	else:
		print "not exist"
	q.wait()
retval = p.wait()
print "overall: " + str(number) + " apps"
